<?php if($action=='view'):?>
    <form method="post" action="<?php echo $this->baseurl("/appstore/manageorders/view/{$oderdata['id']}") ?>">
    <?php App::Helper('Toolbar')->setTitle("#{$oderdata['id']} Order Information")->setBtnSave()->setBtnBack()->Render(array('code'=>'appstore_order_view_top'));?>
    <?php  if(!empty($oderdata))
        {?>
            <table width="100%">
                <tr>
                    <td width="50%" valign="top">
                    <?php
                    echo App::Helper("Html")->getTag("h3","Price and Status");
                    $Grid = App::Module('DataGrid')->setDisplay('FormListing')
                                                   ->addRow("Order Id",$oderdata['id'])
                                                   ->addRow("Qty",$oderdata['qty'])
                                                   ->addRow("Total Cost",App::Helper('Config')->siteInfo('currency') . " {$oderdata['totalcost']}")
                                                   ->addRow("Order Date",App::Helper('Date')->dateFormated($oderdata['orderdate']))
                                                   ->addRow("Payment Method","{$oderdata['paymenttype']}")
                                                   ->addRow("Payment Status",App::Helper('Html')->selectTag("data[Order][paymentstatus]",App::Component('Appstore')->Helper('Data')->getPaymentStatusList(),"{$oderdata['paymentstatus']}"))
                                                   ->addRow("Delivery Status",App::Helper('Html')->selectTag("data[Order][deliverystatus]",App::Component('Appstore')->Helper('Data')->getDeliveryStatusList(),"{$oderdata['deliverystatus']}"))
                                                   ->Render();
                    ?>
                    </td>
                    <td>
                    <?php
                    $shippingaddress = unserialize($oderdata['shippingaddress']);
                    echo App::Helper("Html")->getTag("h3","Shipping Address");
                    $Grid = App::Module('DataGrid')->clear()
                                                   ->setDisplay('FormListing')
                                                   ->addRow("Name","{$shippingaddress['fname']} {$shippingaddress['lname']}")
                                                   ->addRow("Address Line 1","{$shippingaddress['address_line_1']}")
                                                   ->addRow("Address Line 2","{$shippingaddress['address_line_2']}")
                                                   ->addRow("City","{$shippingaddress['city']}")
                                                   ->addRow("State/Province","{$shippingaddress['state']}")
                                                   ->addRow("Postal/Zip Code","{$shippingaddress['zipcode']}")
                                                   ->addRow("Country",App::Helper('Utility')->CountryCodeToName($shippingaddress['country']))
                                                   ->addRow("Email",$shippingaddress['email'])
                                                   ->Render();
                    ?>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <?php
                            echo App::Helper("Html")->getTag("h3","Items Information");
                            $items = App::Model('Item')->findAllByOrderId($oderdata['id']);

                            $Grid = App::Module('DataGrid')->clear();
                            $QTY = 0;
                            $TOTAL = 0;
                            foreach($items['data'] as $item)
                            {
                                $Grid->addRow($item['id'],$item['title'],$item['qty'],$item['unitprice'],$item['totalprice']);
                                $QTY   += $item['qty'];
                                $TOTAL += $item['totalprice'];
                            }
                            $Grid->setHeader(Array("ID","Title","Qty","Unit Price","Total"))
                                 ->setFooter(Array("","","{$QTY}(Total Qty)","","{$TOTAL} (Grand Total)"))
                                 ->Render();
                        ?>
                    </td>
                </tr>
            </table>
    <?php
        }
        else
        {
            echo $this->callElement('default/tools/message', array('caption' =>'Message','type' => 'error', 'message' => 'No Data found for Account'));
        }
        App::Helper('Toolbar')->setBtnSave()->setBtnBack()->Render(array('code'=>'appstore_order_top'));
    ?>
    </form>
<?php else:?>
    <?php
    App::Helper('Toolbar')->setTitle("Manage Orders")->setBtnDelete(array("id"=>"{'mode':'order'}"))->setBtnBack()->Render(array('code'=>'appstore_order_top'));
        if(!empty($oderdata['data']))
        {
            $Grid = App::Module('DataGrid');
            $Grid->setHeader(array($this->get_tag('input',array('type'=>'checkbox','id'=>'checkall','class'=>"checkall")),'#','Name', 'Item Qty','Total Cost','Date','Payment Method','Delivery Status','Payment Status','Options'));
            $Grid->setFooter($oderdata['paging_str']);
            foreach($oderdata['data'] as $key=>$val){
                $shippingaddress = unserialize($val['shippingaddress']);

                $Grid->addRow(
                    $this->get_tag('input',array('type'=>'checkbox','value'=>"{$val['id']}","class"=>"checkrow")),
                    (($oderdata["page"] - 1) * $this->get_config('default_pagination') + $key + 1),
                    "{$shippingaddress['fname']} {$shippingaddress['lname']}",
                    $val['qty'],
                    $val['totalcost'],
                    App::Helper('Date')->dateFormated($val['orderdate']),
                    $val['paymenttype'],
                    $val['deliverystatus'],
                    $val['paymentstatus'],
                    App::load("Helper/Html")->linkTag($this->baseurl('/appstore/manageorders/view/' . $val['id']),App::load("Helper/Html")->imgTag($this->baseurl('/images/admin/view.gif'),NULL,array('title'=>'Edit ','alt' => 'View',"class"=>"icon")),array("title"=>"Edit user information"))
                    . App::load("Helper/Html")->linkTag("javascript:void(0)",App::load("Helper/Html")->imgTag($this->baseurl('/images/admin/remove.gif'),NULL,array('title'=>'Delete','alt'=>'Delete')),array('id'=>'Order_' . $val['id'],'class'=>'link_delete icon', 'title'=>'Order_' . $val['id']))
                    );
            }
            $Grid->Render();
        }
        else
        {
            echo $this->callElement('default/tools/message', array('caption' =>'Message','type' => 'error', 'message' => 'No Data found for Account'));
        }
        App::Helper('Toolbar')->setBtnBack()->Render(array('code'=>'appstore_order_bottom'));
    ?>
<?php endif;?>